/**
 * 地址映射
 * @author luguoxiang
 * @date 2025-05-10
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { BaseEntity, IConfigSchema, LgAutoComplete } from '@/soar';
import api, { basePath } from './api';
import { MenuComponent } from '@/types/interface';

export interface UrlMapping extends BaseEntity {
  /** 创建人 */
  createBy?: string;
  /** 创建时间 */
  createTime?: string;
  /** 更新人 */
  updateBy?: string;
  /** 更新时间 */
  updateTime?: string;
  /**  */
  id?: string;
  /** 名称 */
  name?: string;
  /** 终端类型 */
  groupCode?: string;
  /** 业务类型 */
  bizType?: string;
  /** 映射地址 */
  url?: string;
}

const fieldList: IConfigSchema<UrlMapping>[] = [
  {
    field: 'groupCode',
    label: '分组',
    dataType: 'string',
    table: {
      width: 200,
      sorter: true,
    },
    form: {
      component: LgAutoComplete,
      componentProps: {
        options: () => api.getGroups(),
      },
    },
  },
  {
    field: 'bizType',
    label: '业务类型',
    dataType: 'string',
    table: {
      sorter: true,
    },
    form: {
      component: LgAutoComplete,
      componentProps: {
        options: () => api.getBizTypes(),
      },
    },
  },
  {
    field: 'url',
    label: '映射地址',
    dataType: 'string',
    table: {
      sorter: true,
    },
    form: {
      slots: 'url',
    },
  },
  {
    field: 'name',
    label: '名称',
    dataType: 'string',
    table: {
      width: 200,
    },
  },
];

export default fieldList;

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '地址映射',
    component: () => import('./List.vue'),
    sort: 60,
    keepalive: true,
    icon: 'braces',
    permits: [`GET${basePath}/query`, `GET${basePath}/getGroups`, `GET${basePath}/getBizTypes`],
    elements: [
      { title: '新增', code: 'create', permits: [`POST${basePath}/create`] },
      { title: '更新', code: 'update', permits: [`POST${basePath}/update`, `GET${basePath}/detail`] },
      { title: '删除', code: 'remove', permits: [`POST${basePath}/remove`] },
      { title: '详情', code: 'detail', permits: [`GET${basePath}/detail`] },
      { title: '导入', code: 'import', permits: [`POST${basePath}/import`] },
      { title: '导出', code: 'export', permits: [`GET${basePath}/export`] },
      { title: '清除缓存', code: 'clear-cache', permits: [`POST${basePath}/clear-cache`] },
    ],
  },
];
